var webpack = require('webpack')
var path = require('path')
var HtmlWebpackPlugin = require('html-webpack-plugin')
var fs = require('fs')
var cheerio = require('cheerio')

var myModule = {
  entry: './src/app.main.js',

  output:  {
    filename: 'bundle.js',
    path: path.join(__dirname, 'dist')
  },
  devServer: {
    hot: true,
    progress: true,
    inline: true
  },
  devTools: 'source-map',
  module: {
    loaders: [
      {
        test: /\.js$/,
        loader: 'babel?presets=es2015'
      }
    ]
  },
  babel: {
    presets: ['es2015']
  },
  resolve: {
    extensions: ['', '.js']
  }

}

if (process.env.NODE_ENV === 'prod') {
  myModule.plugins = (myModule.plugins || []).concat([
    new HtmlWebpackPlugin({
      template: 'index.html'
    }),
    new webpack.optimize.UglifyJsPlugin({
      compress: {
        warnings: false
      },
      except: ['$super', '$', 'exports', 'require']    //排除关键字
    })
  ])
} else {
  myModule.output.publicPath = '/'
  myModule.plugins = (myModule.plugins || []).concat([
    new webpack.HotModuleReplacementPlugin()
  ])

}



module.exports = myModule